<title>设置我的资料</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>设置</cite></a>
        <a><cite>我的资料</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">信息</div>
        <div class="layui-card-body" pad15>
            <div class="layui-form layui-form-pane" lay-filter="LAY-user-info-form">
                <div class="layui-form-item">
                    <label for="" class="layui-form-label must">头像</label>
                    <div class="layui-input-block" style="width: 60%;">
                        <div class="layui-upload" id="avatar"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="" class="layui-form-label must">昵称</label>
                    <div class="layui-input-block" style="width: 380px;">
                        <input type="text" name="display_name" lay-verify="required" lay-vertype="tips" placeholder="请输入昵称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="LAY-user-info-formSubmit"><i class="layui-icon layui-icon-release"></i> 提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['index', 'fileUpload', 'baseMethods'], function () {
        const {$, layer, form, baseMethods} = layui, userinfo = AppGeneral.getSystemUser();
        layui.fileUpload.init({
            elem: '#avatar',
            name: 'avatar',
            value: userinfo.avatar,
        });
        form.val('LAY-user-info-form', {
            display_name: userinfo.displayName
        });
        form.on('submit(LAY-user-info-formSubmit)', function(data) {
            layer.confirm('确定提交么？', function() {
                baseMethods.request({
                    url: '/basic/update',
                    type: 'post',
                    data: data.field,
                    done: function (result) {
                        if (result.code === 200) {
                            localStorage.setItem("USERINFO", JSON.stringify($.extend(userinfo, {
                                avatar: data.field.avatar,
                                displayName: data.field.display_name,
                            })));
                            return layer.msg(result.message, {icon: 6})
                        }
                        layer.msg(result.message, {icon: 5});
                    }
                })
            });
        });
    });
</script>
